var common = function(){

	//获取url的信息
	function getLocationHerfxx(path){
		var re = /(\w+):\/\/([^\:|\/]+)(\:\d*)?(.*\/)([^#|\?|\n]+)?(#.*)?(\?.*)?/i;   
	    var arr = path.match(re); 
		return arr;
	}
	
	
	function getCookie(objName){
		var arrStr = document.cookie.split("; ");
		for(var i = 0;i < arrStr.length;i ++){
			var temp = arrStr[i].split("=");
			if(temp[0] == objName){
				return unescape(temp[1]);
			}
		}
	}
	
	
	function loadHeader(el){
		$.get(Constants.admin + "o2o/tpl/common/index_top.html", function(template){
			var menuRactive = new Ractive({
				el: el,
				template: template,
				onrender: function(){
					
				},
				oncomplete: function(){
					var unick = decodeURIComponent(escape(getCookie("_unick")));
					menuRactive.set("zh",unick);
				}
			})
			menuRactive.on({
				doexit:function(){
	        		window.location.href = Constants.loginUrl + "logout?t="+new Date().getTime();
	        	}
			})
		})
		
		
	}
	
	function loadMenu(el){
		$.get(Constants.admin + "o2o/tpl/common/index_menu.html", function(template){
			var menuRactive = new Ractive({
				el: el,
				template: template,
				data: {
					zyhjUrl: Constants.admin,
					jfUrl: Constants.jfUrl
				},
				onrender: function(){
					
				},
				oncomplete: function(){
					$.get(Constants.amUrlPath + "common/getMenu", function(data){
						if(!(data instanceof Object)) return;
						menuRactive.set("menuList", data.child);
						
						$(".dropdown-toggle").click(function () {
		                    $(this).next().slideToggle();
		                    if ($(this).find("i").hasClass("icon-jia")) {
		                        $(this).find("i").removeClass("icon-jia");
		                        $(this).find("i").addClass("icon-jian");
		                    } else {
		                        $(this).find("i").removeClass("icon-jian");
		                        $(this).find("i").addClass("icon-jia");
		                    }
		                });
						$(".dropdown-toggle").eq(0).click();
						$(".nav-list>li>ul>li").find("a").eq(0).addClass("active");
						$(".hp-iframe").attr("src", Constants.admin + data.child[0].child[0].resourceurl);
		                 //获取当前的地址
						 var arr =getLocationHerfxx(location.href); 
						 var http=arr[1]+"://"+arr[2];
						 
						 
						 $(".nav-list a").click(function(){
							 $(".nav-list a").removeClass("active")
							 $(this).addClass("active")
						})
						 
					})
				}
			})
		})
		
		
	}
	
	return {
		loadHeader: loadHeader,
		loadMenu: loadMenu
	}
}();